package com.hongyi.demo.mapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hongyi.demo.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author hongyi
 * @date 2024/7/22 9:46
 */
public interface UserMapper01 extends BaseMapper<User>{

   /**
    * 根据id 查询数据
    * @param id
    * @return
    */
   User queryById(Long id);

//   public List<User> getUsername(String name); // 根据用户的名称进行查询
   public List<User> getUsername(@Param("name") String name); // 根据用户的名称进行查询

   @Select("UPDATE user SET balance = balance - #{money} ${ew.customSqlSegment}")
   void deductBalanceByIds(@Param("money") int money,  @Param("ew") QueryWrapper<User> wrapper);
   List<User> queryUserByIdAndAddr(@Param("ids") List<Long> ids);
//   @Select("SELECT u.* FROM user u INNER JOIN address a ON u.id = a.user_id ${ew.customSqlSegment}")
   List<User> queryUserByWrapper(@Param("ew")QueryWrapper<User> wrapper);
   @Update("UPDATE user SET balance = balance - #{money} WHERE id = #{id}")
   void deductMoneyById(@Param("id") Long id, @Param("money") Integer money);
}

